#include "linux_def.h"
#include "core.h"
#include "event.h"

int event_mutex_timedlock(event_mutex_t *m, int timer, event_t *ev)
{
	if (m->lock){
		if (m->events == NULL)
			m->events = ev;
		else
			m->last->next = ev;

		m->last = ev;
		ev->next = NULL;

		//add_timer(ev, timer);
		//
		return EAGAIN;
	}

	m->lock = 1;
	return E_OK;
}

int event_mutex_unlock(event_mutex_t *m, log_t *log)
{
	event_t *ev;

	if (m->lock == 0)
		return E_FAIL;

	m->lock = 0;
	
	if (m->events){
		ev = m->events;
		m->events = ev->next;

		ev->next = (event_t*)posted_events;
		posted_events = ev;
	}

	return E_OK;
}
